home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’95 / Venus / myenv.h < prev    next >
Encoding:
Text File  |  1994-06-06  |  3.1 KB  |  101 lines  |  [TEXT/KAHL]

  1. //************************************************************************
  2. //
  3. //                            A standard environment
  4. //                                I am accustomed to
  5.  
  6. #pragma once
  7. #ifndef _myenv_h
  8.  
  9. #define _myenv_h
  10. #ifdef __GNUC__
  11. #pragma interface
  12. #endif
  13.  
  14.                 // Strings of symbols
  15.                 // They may be used as a delimiting lines
  16. extern const char _Minuses [];
  17. extern const char _Asteriscs [];
  18. extern const char _Equals [];
  19.  
  20.                 // Print an error message at stderr and    abort
  21. volatile void _error(
  22.     const char * message,            // Message to be printed
  23.     ...                             // Additional args like in printf()
  24.        );
  25.                 // Set a custom fuction that would perform abort
  26.                 // nil means set up the standard abort function
  27. void set_abort_function(const volatile void (*custom_abort)(void));
  28.  
  29.                 // Print a message at stderr
  30. void message(
  31.     const char * text,                // Message to be printed
  32.     ...                             // Additional args to printf
  33.        );
  34.  
  35. class ErrHandler
  36. {
  37.     Boolean raise_hell;                // Raise the hell in case of error?
  38.     Boolean was_error;                // Has an error sneaked in whilst we're lenient?
  39.     
  40. public:
  41.     ErrHandler(void);
  42.     ~ErrHandler(void) {}
  43.     void error(const char * message,...);
  44.     void lenient(void);                        // Be lenient
  45.     Boolean was_ok(void);                    // Have we failed?
  46. };
  47.  
  48. //------------------------------------------------------------------------
  49. //                        Verify the assertion
  50.  
  51. #ifndef assert
  52. #define assert(ex) \
  53.         (void)((ex) ? 1 : \
  54.               (_error("Failed assertion " #ex " at line %ld of `%s'.", \
  55.                __LINE__, __FILE__), 0))
  56. #endif
  57. #define assertval(ex) assert(ex)
  58.  
  59. #define assure(expr,message)                \
  60.     if    (expr) ;                \
  61.     else _error("%s at line %ld of '%s'.",message,__LINE__, __FILE__);
  62.  
  63.                                         // Execute the function 'ex' and make sure
  64.                                         // it return noErr
  65. #define do_well(ex) \
  66.         { OSErr err = (ex); if( err != noErr ) \
  67.               _error("Failed call " #ex " with error %ld at line %ld of `%s'.", \
  68.                err, __LINE__, __FILE__); }
  69.  
  70. //------------------------------------------------------------------------
  71. //                             Notification posting
  72. // The set of functions below let a (backgound) application to post 
  73. // synchronous or asynchronous notification messages to the user.
  74. // Synchronous posting means that function does not return until the
  75. // notification message is displayed and the user dismisses it.
  76. // In asynchronous mode, the posting function returns as soon as the
  77. // message is queued into the notification queue (but not yet displayed!).
  78. // 
  79.  
  80. void notify_and_wait(const char * messg,...);
  81. void notify(const char * messg,...);
  82.  
  83. //------------------------------------------------------------------------
  84. //                            Sound playing on errors
  85.  
  86. void set_error_sound(Str255 sound_name);
  87.  
  88. //------------------------------------------------------------------------
  89. //                            Macintosh System Utilities
  90.  
  91. void Initialize_MAC(void);
  92. void sleep(const int nticks);            // Generous suspension for a specified no. of ticks
  93.  
  94.                                         // Launch an application and have it handle the
  95.                                         // specified file, as if the file were
  96.                                         // "double-clicked"
  97. void open_selection(const char * full_path_name);
  98.  
  99.  
  100. #endif
  101.